package se.webbzon.oschi01.json;

import java.io.IOException;
import java.io.PrintStream;

public class JsonBoolean implements JsonLeaf<Boolean> {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 4029417484558968050L;
	
	protected boolean b;
	
	public JsonBoolean() {
		this(false);
	}
	
	public JsonBoolean(JsonBoolean other) {
		this(other.b);
	}
	
	public JsonBoolean(boolean b) {
		this.b = b;
	}

	@Override public Type getType() {
		return JsonType.Type.Boolean;
	}
	
	@Override public String toString() {
		return b ? "true" : "false";
	}
	
	@Override public int hashCode() {
		return b ? 0 : 1;
	}

	@Override public Boolean getValue() {
		return b;
	}

	@Override public void setValue(Boolean b) {
		this.b = b == null ? false : b;
	}

	@Override public JsonBoolean clone() {
		return new JsonBoolean(this);
	}

	@Override public int compareTo(JsonLeaf<Boolean> o) {
		return getValue().compareTo(o.getValue());
	}
	
	@Override public boolean equals(Object obj) {
		if (obj instanceof JsonLeaf)
			return getValue().equals(((JsonLeaf<?>) obj).getValue());
		else
			return false;
	}
	
	@Override public void printTo(PrintStream ps) throws IOException {
		ps.print(toString());
	}
	
}
